<template>
  <div class="student">
    <h2>学生姓名 {{ name }}</h2>
    <h2>性别 {{ sex }}</h2>
    <button @click="sendStudentName">把学生名给School组件</button>
  </div>
</template>
<script>
// 引入pubsub
import pubsub from "pubsub-js";
export default {
  name: "Student",
  data() {
    return {
      name: "张三",
      sex: "男",
    };
  },
  methods:{
    sendStudentName(){
      // 发布消息  发布消息hello 发布消息名要和订阅的消息名一致
      pubsub.publish("hello",this.name);
    }
  },
};
</script>

<style scoped lang="less">
.student {
  background-color: pink;
  padding: 5px;
  margin-top: 30px;
}
</style>
